$(function(){

	// 地址动态替换
	//查找当前拥有selected样式的按钮
	let currentAddress = $('.addressInfo .selected');
	let addressInfo =  '寄送至: ' + currentAddress.next().find('.consignee_address').text() +
					'收货人 ' + currentAddress.next().find('.consignee_name').text() +
					' ' +  currentAddress.next().find('.consignee_phone').text()
	$('.fc-receiverInfo').text(addressInfo);

	$(".addressInfo").on('mouseover', '.address',function(){
		$(this).addClass("address-hover");	
	}).on('mouseout', '.address',function(){
		$(this).removeClass("address-hover");
	});

	// 点击提交、是否有无货商品
	$(".submit a").click(function () {
		if ($('.no-goods').length > 0) {
			alert("选购的商品中有库存不足的商品、请重新选购");return false;
		}
		// 获取地址id、可以伪造post请求
		let address_id = $('.addressInfo .selected').attr('data-id');
		// 获取领取的id
		let receive_id = $("input[name='coupon']:checked").val();

		location.href='pay?id=' + address_id + '&receive_id=' + receive_id;
	})
})

$(function(){
	$(".addressInfo").on('click', '.name', function(){
		 $(this).addClass("selected").parent().siblings().find('.name').removeClass("selected");
		let currentAddress = $('.addressInfo .selected');
		let addressInfo =  '寄送至: ' + currentAddress.next().find('.consignee_address').text() +
			'收货人 ' + currentAddress.next().find('.consignee_name').text() +
			' ' +  currentAddress.next().find('.consignee_phone').text()
		$('.fc-receiverInfo').text(addressInfo);
	});
	$(".payType li").click(function(){
		 $(this).addClass("selected").siblings().removeClass("selected");
	});
})
